
// 新增页面表单编辑后事件

import afterEditForm from '../request/afterEditForm';

export default async function(props, moduleId, key, value, oldValue, func_type = '1') {
    const {
        humanResourceOrganizationValue: {
            refpk
        },
        form: {
            getAllFormValue,
            setAllFormValue,
            setFormItemsDisabled
        },
        cardTable: {
            setValByKeyAndIndex,
            getAllRows
        }
    } = this.props;
    if (moduleId === 'hi_psnjob_h' && key === 'begindate') {
        let psnjobData = getAllRows('hi_psnjob');
        if (psnjobData.length === 1 && !psnjobData[0].values.begindate.value) {
            setValByKeyAndIndex('hi_psnjob', 0, 'begindate', value)
        }
    }
    let postData = {
        areaCode: moduleId,
        func_type: func_type,
        key: key,
        model: getAllFormValue(moduleId),
        pk_org: refpk
    };

    try {
        let res = await afterEditForm(postData);
        if(res.data.disableItem) {
            Object.keys(res.data.disableItem).forEach((key) => {
                setFormItemsDisabled(moduleId, {
                    [key]: res.data.disableItem[key]
                });
            });
        }
        let formData = res.data && res.data.formData[moduleId];

        setAllFormValue({
            [moduleId]: formData
        });
    }
    catch(e) {
    }
}
